package cn.qyd.io;

import cn.qyd.common.Person;

import java.io.*;

/**
 * @author 邱运铎
 * @date 2024-03-18 1:01
 */
public class ObjectStreamDemo {
    public static void main(String[] args) {
        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src\\cn\\qyd\\io\\Person.txt"));
            Person person = new Person("qiuyunduo",18);
            oos.writeObject(person);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            ObjectInputStream os = new ObjectInputStream(new FileInputStream("src\\cn\\qyd\\io\\Person.txt"));
            Object o = os.readObject();
            System.out.println((Person)o);
        } catch (IOException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
